import { Message } from 'element-ui'

const state = {
  token: '' || JSON.parse(window.localStorage.getItem('System_TOKEN'))
}
const mutations = {
  SET_TOKEN (store, value) {
    store.token = value
    window.localStorage.setItem('System_TOKEN', JSON.stringify(value))
  },
  SET_LOGIN_OUT (store, value) {
    store.token = ''
    window.localStorage.removeItem('System_TOKEN')
  }
}
const actions = {
  LOGIN_UP (context, data) {
    // const { data: res } = await login()
    // console.log(res)
    context.commit('SET_TOKEN', data)
    // window.localStorage.setItem('System_TOKEN', JSON.stringify(this.form))
    Message.success('登录成功')
    // return res
  },
  async LOGIN_OUT (context, data) {
    // const res = await loginOutAPI()
    // if(res.status === 200) {
    // context.commit('SET_LOGIN_OUT', data)
    Message.success('退出登录成功')
    window.localStorage.removeItem('System_TOKEN')
    // }
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
